<template>
  <div class='container'>

    <div class="enter_title">
        <h2 style="background:#265eff;">社区通-居民自查自报</h2>
    </div>
    <van-tabs class='van-tabs-container' scrollspy  sticky  v-model="active" :ellipsis=false  title-active-color='rgba(38, 94, 255, .8)' color="rgba(38, 94, 255, .8)" 	 >
      <van-tab title-style='font-size: 16px; margin-right: 20px; margin-left: 15px;' class='van-tabs-item' title="基本信息" name="1" ><PersonMsg style='margin-top: 18px' ref='personMsg'></PersonMsg></van-tab>
      <van-tab title-style='font-size: 16px; margin-right: 20px;' class='van-tabs-item' title="社区防控措施调查" name="2"><controls-workable style='margin-top: 8px' ref='controls'></controls-workable></van-tab>
      <van-tab title-style='font-size: 16px; margin-right: 20px;' class='van-tabs-item' title="特殊人员信息" name="3"><SpecialPersonnel style='margin-top: 18px' ref='specialPersonnel'></SpecialPersonnel></van-tab>
      <van-tab title-style='font-size: 16px; margin-right: 20px;' class='van-tabs-item' title="生活需求" name="4"><life-needs style='margin-top: 18px' ref='lifeNeeds' ></life-needs></van-tab>
      <van-tab title-style='font-size: 16px; margin-right: 20px;' class='van-tabs-item' title="额外信息" name="5"><Additionalnfor style='margin-top: 18px' ref='additionlnfor' ></Additionalnfor></van-tab>
      <van-tab title-style='font-size: 16px; margin-right: 20px;' class='van-tabs-item' title="线索建议" name="6"><ReportClues style='margin-top: 18px;margin-bottom: 110px' ref='reportClues'></ReportClues></van-tab>
      <!--<van-tab class='van-tabs-item' title="流动人员信息" name="7"><PersonFlow></PersonFlow></van-tab>-->
    </van-tabs>
    <div class='footer'>
      <button class="form-submit" type="submit" @click="submitClick">提交</button>
    </div>
  </div>
</template>

<script>
import DailyList from '@/components/dailylist/dailylist';
import ControlsWorkable from '@/components/home/controlsWorkable';
import LifeNeeds from '@/components/home/lifeNeeds';
import Additionalnfor from '@/components/home/additionalnfor';
import ReportClues from '@/components/home/reportClues';
import PersonMsg from '@/components/home/personMsg';
import SpecialPersonnel from '@/components/home/specialPersonnel';
import PersonFlow from '@/components/home/personFlow';
import { newquestionnaireData ,queryCityData} from '@/assets/js/service'
import Vue from 'vue'
import Tab from 'vant/lib/Tab';
import Tabs from 'vant/lib/Tabs';
import 'vant/lib/Tabs/style';
 Vue.use(Tab);
 Vue.use(Tabs);
export default {

 components:{
    DailyList,
    ControlsWorkable,
    LifeNeeds,
    Additionalnfor,
    ReportClues,
    PersonMsg,
    SpecialPersonnel,
    PersonFlow
 },
 data() {
    return {
      active: 1,
      epidemicData: {
        "age": 0,
        "contactHubei": 0,
        "contactWuhan": 0,
        "createTime": "2020-02-07T03:20:11.528Z",
        "currentCity": "string",
        "currentCountry": "string",
        "currentCounty": "string",
        "currentLocation": "string",
        "currentProvince": "string",
        "currentVillage": "string",
        "familyCountInWuhan": 0,
        "familyNameInWuhan": "string",
        "firstSymptomDate": "string",
        "goToDoctor": 0,
        "guardianIdNumber": "string",
        "guardianName": "string",
        "healthCondition": 0,
        "hubeiTouchHistory": 0,
        "id": 0,
        "idNumber": "string",
        "medicalHistory": "string",
        "medicalHospital": "string",
        "medicalResult": "string",
        "name": "string",
        "phone": "string",
        "pregnant": 0,
        "residence": "string",
        "sex": 0,
        "symptom": "string",
        "toHubei": 0,
        "toWuhan": 0,
        "touchPersonIsolation": 0,
        "touchPersonLocation": "string",
        "touchPersonName": "string",
        "touchPersonPhone": "string",
        "visitDate": "string",
        "visitPerson": "string",
        "visitPersonOrg": "string",
        "visitPersonPhone": "string",
        "workOrg": "string",
        "wuhanTouchHistory": 0
      }
    };
  },
  methods: {
    submitClick() {
      console.log('常住地' + this.$refs.personMsg.residence)
      let that = this;
      console.log('生活物资' + this.$refs.lifeNeeds.life_needs);
      console.log(this.$refs.personMsg.phoneModel);
      if(this.$refs.personMsg.phoneModel == ''){
         window.vm.$vux.toast.text('电话不能为空', 'center')
          return;
      }
      if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test( this.$refs.personMsg.phoneModel))){
        // window.vm.$vux.toast.text('电话填写有误', 'center')
        // return;
         if(!(/^([0-9]{3,4}-)?[0-9]{7,8}$/.test(this.$refs.personMsg.phoneModel))){
              window.vm.$vux.toast.text('电话填写有误', 'center')
              return;
           }
      }
      if(this.$refs.personMsg.idNumber == ''){
         window.vm.$vux.toast.text('身份证号不能为空', 'center')
          return;
      }
      let pattern = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/;
      if(!pattern.test(this.$refs.personMsg.idNumber)) {
        window.vm.$vux.toast.text('身份证号填写有误', 'center')
        return;
      }
      // console.log(pattern.test(this.$refs.personMsg.idNumber))
      if(this.$refs.personMsg.fever == 1){
        if(this.$refs.personMsg.temperatureModel == ''){
         window.vm.$vux.toast.text('体温不能为空', 'center')
            return;
        }
         let temperatureValue = (this.$refs.personMsg.temperatureModel.match(/^(\-?\d{0,2})(\.\d{0,2})?/)||[''])[0];
      console.log(this.$refs.personMsg.temperatureModel.length)
      console.log(this.$refs.personMsg.temperatureModel.search('.'))
      let temVal;
      if(temperatureValue > 42 || temperatureValue < 35 ){
        temVal = false;
      } else{
        if(this.$refs.personMsg.temperatureModel.search('.') != -1 && this.$refs.personMsg.temperatureModel.length =='4'){
           temVal = true;
        } else {
          temVal = false;
        }
      }
      console.log(temVal);

      if(!temVal){
        window.vm.$vux.toast.text('体温填写有误', 'center')
        return;
      }
      }


       if(that.$verification(that.$refs.personMsg.nameModel,0,"姓名")&&that.$verification(that.$refs.personMsg.phoneModel,0,"电话")&&that.$verification(that.$refs.personMsg.residence,0,"所住区域")) {
         var param={
          "name": this.$refs.personMsg.nameModel,
          "sex": this.$refs.personMsg.genderModel,
          "age": Number(this.$refs.personMsg.ageModel),
          "phone": this.$refs.personMsg.phoneModel,
          "idNumber": this.$refs.personMsg.idNumber,
          "pregnant": this.$refs.personMsg.pregnant, //0 否，1 是否为妇女
          "residence": this.$refs.personMsg.residence,//常住地
          "community": this.$refs.personMsg.community,
          "building": this.$refs.personMsg.building,
          "unit": this.$refs.personMsg.unit,
          "backToWuhan": this.$refs.personMsg.backToWuhan,
          "roomNumber": this.$refs.personMsg.roomNumber,
          "widows": this.$refs.personMsg.widows, //0 否，1 是否为老人
          "symptom": this.$refs.personMsg.symptoModel.toString(), //'症状（0:无，1:干咳，2:咽痛，3:发热，4:寒战，5:鼻塞）',
          "diagnosis": this.$refs.personMsg.diagnosis,//是否确诊 0 否 1 疑似 2 确诊
          // 'medicalConditionSymptom': this.$refs.personMsg.medicalConditionSymptom,
          // 'medicalConditionDiagnosed': this.$refs.personMsg.medicalConditionDiagnosed,
          "fever": this.$refs.personMsg.fever,
          "backDate": this.$refs.personMsg.queryTime,
          "temperature": this.$refs.personMsg.temperatureModel,
          "touchPersonIsolation": this.$refs.personMsg.touchPersonIsolation,
          "touchPersonLocation": this.$refs.personMsg.touchPersonLocation,
          "touchPersonPhone": this.$refs.personMsg.touchPersonPhone,
          "touchPersonName": this.$refs.personMsg.touchPersonName,
          "medicalAdvice": this.$refs.personMsg.medicalAdvice,
          "communityTour": this.$refs.controls.community_tour,//是否有社区巡查
          "disinfection": this.$refs.controls.disinfection,//是否每日消毒
          "accessControl": this.$refs.controls.access_control,//是否出入管控
          "concreteMeasure": this.$refs.controls.concrete_measure.toString(),//具体措施
          "specialPersonnelType": this.$refs.specialPersonnel.special_personnel_type,//特殊人员类型
          "objective": this.$refs.specialPersonnel.objective,//目的
          "temporaryResidence": this.$refs.specialPersonnel.temporary_residence,//临时住所
          "servicePlaces": this.$refs.specialPersonnel.service_places,//服务地点
          "lifeNeeds": this.$refs.lifeNeeds.life_needs.toString(),//生活物资
          "otherLifeNeeds": this.$refs.lifeNeeds.other_life_needs,//其他生活物资
          "fixedWork": this.$refs.additionlnfor.fixed_work,//是否有固定工作
          "workOrg": this.$refs.additionlnfor.work_org,//工作单位
          "unemployment": this.$refs.additionlnfor.unemployment,//是否失业待工作
          "fixedIncome": this.$refs.additionlnfor.fixed_income,//是否有固定收入
          "medicalHistory": this.$refs.additionlnfor.medical_history,//本人是否有其他疾病
          "relativesDiagnosed": this.$refs.additionlnfor.relatives_diagnosed,//是否有亲友患病
          "relativesDied": this.$refs.additionlnfor.relatives_died,//是否近期有亲友去世
          "divorced": this.$refs.additionlnfor.divorced,//是否离异
          "clueType": this.$refs.reportClues.checkClue,
          "clueDescribe": this.$refs.reportClues.clue_describe,
      };
      let obj = JSON.stringify(param);
      localStorage.setItem('epidemicData', obj);
      console.log('1111' +this.getCurrentDate().toString())
      newquestionnaireData(param,function(res){
                        console.log("返回正常questionnaireData",res)
                        if(res.success){

                            that.$showBottomToast("上报成功")
                            that.$router.push({ path: '/reportSuccess' , query: {'name': that.$refs.personMsg.nameModel, 'idNumber': that.$refs.personMsg.idNumber,'phone': that.$refs.personMsg.phoneModel}})
                            //_this.showconfirm=true;
                        }else{
                            that.$showBottomToast("请求数据异常！")
                        }
                    })
       }

      this.epidemicData.age = Number(this.$refs.personMsg.ageModel);
      this.epidemicData.name = this.$refs.personMsg.nameModel;
      this.epidemicData.idNumber = this.$refs.personMsg.idNumber;
      this.epidemicData.sex = this.$refs.personMsg.genderModel;
      this.epidemicData.pregnant = this.$refs.personMsg.pregnant;

    },



    getCurrentDate(){
       const timeStr = '-';
       const curDate = new Date();
       const curYear =curDate.getFullYear();  //获取完整的年份(4位,1970-????)
       const curMonth = curDate.getMonth()+1;  //获取当前月份(0-11,0代表1月)
       const curDay = curDate.getDate();       //获取当前日(1-31)
       const curWeekDay = curDate.getDay();    //获取当前星期X(0-6,0代表星期天)
       const curHour = curDate.getHours();      //获取当前小时数(0-23)
       const curMinute = curDate.getMinutes();   // 获取当前分钟数(0-59)
       const curSec =curDate.getSeconds();      //获取当前秒数(0-59)
       const Current= curYear+timeStr+curMonth+timeStr+curDay ;
       return Current;
    }
  }
}
</script>
<style lang="less" scoped>
.container {
  position: relative;
  min-height: 100%;
  width: 100%;
  background: #fff;
  padding:0px;
}
.enter_title{
    width: 100%;
    height: 9vh;
    color: white;
    line-height: 9vh;
    text-align: center;
}
// .mui-bar.mui-bar-nav {
//   position: relative;
//   height: 0.9rem;
//   line-height: 0.9rem;
//   font-size: 0.26rem;
//   color: #fff;
//   text-align: center;
//   background-color: rgba(38, 94, 255, .8);
// }
.van-tabs-container {
  padding-bottom: 60px;
  width: 100% !important;
}
.van-tab {
  margin-right: 10px;
  margin-left: 10px;
  padding: 0 10px !important;
}
.van-tabs-item {
  padding: 0 10px !important;
  // margin-top: 0.3rem;
  // margin-right: 0.05rem;
}
.footer {
  position: fixed;
  left: 0;
  bottom: 0.1rem;
  width: 100%;
  height: 50px;
  z-index: 100;
  .form-submit{
    width: 90%;
    margin-left: 5%;
    height: 50px;
    background: #265eff;
    border-radius: 8px;
    color: white;
    font-size: 15px;
    border: none;
    outline: none;
  }
}

</style>
